package com.zxh.listdemo.listener;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.widget.AbsListView;

import com.squareup.picasso.Picasso;

import java.lang.ref.WeakReference;

/**
 * Created by zhangxuehui on 2018/2/28.
 */

public class PicssoScrollListener implements AbsListView.OnScrollListener {
    private final WeakReference<Context> mContext;

    public PicssoScrollListener(Context context) {
        mContext = new WeakReference<>(context);
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        final Picasso picasso = Picasso.with(mContext.get());
        if (scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_TOUCH_SCROLL) {
            picasso.resumeTag(mContext.get());
        } else {
            picasso.pauseTag(mContext.get());
        }
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    }
}
